package com.xx.pmis.web.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class LogoutAction extends DispatchAction {
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession(false);
		Logger log = Logger.getLogger(this.getClass());
		if (session != null) {
			String username = (String) session.getAttribute("username");
			session.invalidate();
			log.info("User: " + username + " logout!");
			// session.removeAttribute("username");
			return mapping.findForward("success");
		} else {
			return mapping.findForward("fail");
		}
	}
}
